﻿using NAudio.Wave;
using SpeechLib;
using static System.Console;

namespace demo
{
    internal class Program
    {
        static void Main(string[] args)
        {
            WriteLine("1:语音合成\r\n2:任务查询\r\n");
            string line = ReadLine().Trim();
            switch (line)
            {
                case "1":
                    语音合成();
                    break;

                case "2":
                    {
                        Write("任务ID:");
                        string task_id = ReadLine();
                        语音任务查询(task_id);
                    }
                    break;
            }
        }

        private static void 语音任务查询(string task_id)
        {
            var res = SpeechApi.LongSpeechTaskCheck(task_id);
            WriteLine($"任务状态:{res.status}");
            if (res.status == 任务状态.Success)
            {
                WriteLine($"下载链接:\r\n{res.res.tasks_info[0].task_result.speech_url}");

                //下载

            }
            ReadKey(true);
        }

        private static void 语音合成()
        {
            //以换行为段落
            string txt = File.ReadAllText("speech.txt");
            string[] textArray = txt.Split("\r\n", StringSplitOptions.RemoveEmptyEntries);
            List<string> list = new List<string>();
            foreach (var text in textArray) list.Add(text.Trim());

            SpeechSetting speechSet = SpeechSetting.Instance;
            WriteLine($"{speechSet.播音员}，语速{speechSet.语速}，音频格式:{speechSet.音频格式}。\r\n调用api...\r\n");


            var res = SpeechApi.LongSpeech(list.ToArray(), speechSet.播音员, speechSet.语速, speechSet.音频格式);
            if (res.success)
            {
                WriteLine($"语音合成任务创建完成：{res.res.task_id}");
            }
            else
            {
                WriteLine("合成失败");
            }
            ReadKey(true);
        }
    }

}